//
//  ChangeLoginPasswordViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/28.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "ChangeLoginPasswordViewModel.h"
#import "AdressFootView.h"
#import "ChangeLoginPWTableViewCell.h"
#import "AdressMarkModel.h"
#import "LoginModel.h"

@interface ChangeLoginPasswordViewModel ()<UITableViewDataSource,UITableViewDelegate>
{
    AdressMarkModel * adressModel;
    AdressFootView * footview;
}
@end

@implementation ChangeLoginPasswordViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        adressModel = [AdressMarkModel new];
        superView.backgroundColor = [UIColor whiteColor];
        tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        tableView.mj_footer.hidden = YES;
        tableView.mj_header.hidden = YES;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.rowHeight = kHeightProportion_In_iPhoneTriploid(44);
        tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(10))];
        tableView.tableFooterView = [self createFootView];
        [superView addSubview:tableView];
    }
    return self;
}

-(UIView *)createFootView{
    footview = [[AdressFootView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(144))];
    [[footview.severBut rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        kKeyboardEndEditing
        [self requestData];
    }];
    return footview;
}

#pragma mark -- UITableViewDataSource,UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ChangeLoginPWTableViewCell * cell = [ChangeLoginPWTableViewCell cellWithTableView:tableView];
    cell.row_Num = indexPath.row;
    cell.changeMarkModel = adressModel;
    cell.Block_ChangeTextField = ^{
        [self changeButent];
    };
    return cell;
}

-(void)changeButent{
    if (adressModel.lineOneStr.length>0 && adressModel.lineTwoStr.length>0 && adressModel.lineThreeStr.length>0) {
        footview.severBut.backgroundColor = kColor_Rule_Yellow;
        footview.severBut.enabled = YES;
    }else{
        footview.severBut.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
        footview.severBut.enabled = NO;
    }
}


#pragma mark -- 数据请求
-(void)requestData{
    if (self.userInforData.length == 0) return;
    LoginModel * loginModel = [NSKeyedUnarchiver unarchiveObjectWithData:self.userInforData];
    NSDictionary * dic = @{@"userId":koString(loginModel.data.userId),@"password":koString(adressModel.lineOneStr),@"newPassword":koString(adressModel.lineTwoStr),@"confirmPassword":koString(adressModel.lineTwoStr)};
    [GLGWRequestTool POST:[NSString stringWithFormat:@"%@%@",kApiPrefix,kModifyPassword] lodingView:nil lodingTextString:@"" isLoding:YES parameters:dic success:^(id  _Nullable response) {
        
    } failure:^(NSError * _Nullable error) {
        
    }];
}


@end
